package domain

import (
	"errors"
	"net/mail"
)

// Email 值对象
type Email struct {
	value string
}

// NewEmail 创建一个新的 Email 值对象
func NewEmail(email string) (*Email, error) {
	if email == "" {
		return nil, errors.New("email cannot be empty")
	}

	// 验证 Email 格式
	_, err := mail.ParseAddress(email)
	if err != nil {
		return nil, errors.New("invalid email format")
	}

	return &Email{value: email}, nil
}

// GetValue 获取 Email 的值
func (e *Email) GetValue() string {
	return e.value
}

// Equal 判断两个 Email 值对象是否相等
func (e *Email) Equal(other *Email) bool {
	return e.value == other.GetValue()
}

// String 返回 Email 的字符串表示
func (e *Email) String() string {
	return e.value
}
